﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MySql.Data;
using MySql.Data.MySqlClient;
using FindIt.DAL;
using FindIt.BLL;
using System.Drawing;

namespace FindIt.UI.Pages
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Button1Test_Click(object sender, EventArgs e)
        {
            //string strSql = "select * from Find it where tbluser='" + this.Label3.Text + "'";
            //DataTable dsTable = dbObj.GetDataSet(strSql, "find it");
            //if (dsTable.Rows.Count > 0)
            //{
            //    Response.Write(ccObj.MessageBox("Sorry,this username is already taken", "Register.aspx"));
            //}
            //else
            //{
            //    Response.Write(ccObj.MessageBox("Congratulation,Your registration was successful"));
            //}
        }

        protected void Button1Back_Click(object sender, EventArgs e)
        {
            Response.Redirect("Default.aspx");
        }

        protected void btnRegister_Click(object sender, EventArgs e)
        {
            string firstName = txtFirst.Text;
            string lastName = txtLast.Text;
            string username = txtUN.Text;
            string password = txtPass.Text;
            string email = txtEmail.Text;

            User user = new User(username, password, firstName, lastName, email, FindIt.BLL.User.RoleType.WU);
            bool success = user.AddUserToDB();

            if (success)
            {
                WaitingUser wu = new WaitingUser(username, WaitingUser.StatusType.waiting);
                wu.AddWUToDB();
                lblMessage.ForeColor = Color.Black;
                lblMessage.Text = "Your request has been processed.<br>Please wait for approval from the System Administrator";
            }

            else
            {
                lblMessage.ForeColor = Color.Red;
                lblMessage.Text = "Sorry, the username is already taken.<br>Please try an alternative";
            }
        }
    }
}